package org.yu.team2023.flashdays.net;

import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
import org.yu.team2023.flashdays.FlashDays;

public class FlashNet {
    public static final String VERSION = "1.0";
    public static SimpleChannel channel;
    private static int ID = 0;

    public static int nextID() {
        return ID++;
    }

    public static void registerMessage() {
        channel = NetworkRegistry.newSimpleChannel(
                new ResourceLocation(FlashDays.MODID, "net_data"),
                () -> VERSION,
                (version) -> version.equals(VERSION),
                (version) -> version.equals(VERSION)
        );
        channel.messageBuilder(DamageParticlePackage.class, nextID())
                .encoder(DamageParticlePackage::toBytes)
                .decoder(DamageParticlePackage::create)
                .consumerMainThread(DamageParticlePackage::handle)
                .add();


        channel.messageBuilder(TreasureUpgradeRequestPackage.class, nextID())
                .encoder(TreasureUpgradeRequestPackage::toBytes)
                .decoder(TreasureUpgradeRequestPackage::create)
                .consumerMainThread(TreasureUpgradeRequestPackage::handle)
                .add();

    }
}
